var app = new Vue({
    el: "#player",
    data: {
        // 查询关键字
        query: "",
        // 歌曲数组
        musicList: [],
        // 歌曲地址
        musicUrl: "",
        // 歌曲封面
        musicCover: "../images/play.png",
        // 歌曲评论
        hotComments: [],
        // 动画播放状态
        isPlaying: false,
        // 遮罩层的显示状态
         isShow: false,
        // mv地址
         mvUrl: "",
         toplist:[],
         singername:"",
         singercover:"",
         detaillist:["dwadawd","dwawdawd"],
         newmv:[],
         newmv1:[],
         newmv2:[],
         newmv3:[],
         
         banner:[]
    },
  
    methods: {
        // 歌曲搜索
        searchMusic: function() {
            var that = this;
            axios.get("http://localhost:3000/search?keywords=" + this.query).then(
                function(response) {
                    // console.log(response);
                    that.musicList = response.data.result.songs;
                    // console.log(response.data.result.songs);
                },
                function(err) {}
            );
            
            axios.get("http://localhost:3000/top/artists?offset=0&limit=10").then(
                function(response) {
                     console.log(response.data.artists);
                      that.toplist = response.data.artists;
                   //  console.log(response);
                },
                function(err) {}
            );
        },
        // 歌曲播放
        playMusic: function(musicId) {
              // console.log(musicId);
            var that = this;
            // 获取歌曲地址
            axios.get("http://localhost:3000/song/url?id=" + musicId).then(
                function(response) {
                   //  console.log(response);
                   //  console.log(response.data);
                    that.musicUrl = response.data.data[0].url;
                },
                function(err) {}
            );

            // 歌曲详情获取
            axios.get("http://localhost:3000/song/detail?ids=" + musicId).then(
                function(response) {
                   //  console.log(response);
                   // console.log(response.data.songs[0].al.picUrl);
                    that.musicCover = response.data.songs[0].al.picUrl;
                },
                function(err) {}
            );

            // 歌曲评论获取
            axios.get("http://localhost:3000/comment/hot?type=0&id=" + musicId).then(
                function(response) {
                    //console.log(response);
                     console.log(response.data.hotComments);
                    that.hotComments = response.data.hotComments;
                },
                function(err) {}
            );
        },
        top:function(){
            var that = this;
            axios.get("http://localhost:3000/top/artists?offset=0&limit=10").then(
                function(response) {
                    // console.log(response);
                   that.toplist = response.data.artists;
                    // console.log(response.data.artists);
                },
                function(err) {}
            );
           
            
        },
        getid:function(){
            var url = window.location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                var strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
                }
            }
            if(theRequest.id!=undefined)
            {
                var that = this;
                axios.get("http://localhost:3000/artist/desc?id=" + theRequest.id).then(
                    function(response) {
                        // console.log(response.data);
                        that.detaillist=response.data
                    
                      
                    },
                    function(err) {}
                
                );
                axios.get("http://localhost:3000/artist/detail?id=" + theRequest.id).then(
                    function(response) {
                         console.log(response.data.data.artist);
                         that.singername=response.data.data.artist.name
                         that.singercover=response.data.data.artist.cover
                      
                    
                      
                    },
                    function(err) {}
                
                );
               console.log(theRequest.id)
            }
          
       
           return theRequest

        },
        info:function(){
            var that = this;
            axios.get("http://localhost:3000/artist/desc?id=" + singerid).then(
                function(response) {
                     console.log(response.data);
                    that.detaillist=response.data
                   window.open('../src/details.html'+"?id="+singerid)
                  
                },
                function(err) {}
            
            );
        },
        detail:function(singerid){
           
                   window.open('../src/details.html'+"?id="+singerid,'_self')
            
            
       
            
        },
        getnewmv:function(){
            var that = this;
            axios.get("http://localhost:3000/mv/first?limit=10" ).then(
                function(response) {
                 
                    that.newmv=response.data
                    that.newmv1=response.data.data[0]
                    that.newmv2=response.data.data[1]
                    that.newmv3=response.data.data[7]
                    console.log(that.newmv3.name);
                
                  
                },
                function(err) {}
            
            );
            axios.get("http://localhost:3000/banner" ).then(
                function(response) {
                     //console.log(response.data);
                   
                
                  
                },
                function(err) {}
            
            );

        },

        // 歌曲播放
        play: function() {
             console.log("播放");
            this.isPlaying = true;
        },
        // 歌曲暂停
        pause: function() {
           // console.log("暂停");
            this.isPlaying = false;
        },
        // 播放mv
        playMV: function(mvid) {
            var that = this;
            axios.get("http://localhost:3000/mv/url?id=" + mvid).then(
                function(response) {
                //    console.log(response);
                   console.log(response.data.data.url);
                
                 // that.$refs.audio.pause();

                
                    that.isShow = true;
                    that.mvUrl = response.data.data.url;
                },
                function(err) {}
            );
        },
        // 隐藏
        hide: function() {
            this.isShow = false;

            //关闭遮罩层的同时停止播放mv
            console.log("关闭mv")
            this.mvUrl="";
        }
    },
    mounted(){
      this.getid()
     this.top()
     this.getnewmv()
    },
});
